package com.example.recipesapp

import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import android.os.Environment
import com.example.recipesapp.ImageManager.getStorageDir
import java.io.File
import java.io.FileOutputStream
import java.net.URI

object ImageManager {
    // 获取图片存储目录
    fun getStorageDir(context: Context, type: String): File {
        return File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), type).apply {
            if (!exists()) mkdirs()
        }
    }

    // 保存图片并返回路径
    fun saveImage(context: Context, bitmap: Bitmap, type: String, fileName: String): String {
        val outputFile = File(getStorageDir(context, type),fileName)
        FileOutputStream(outputFile).use { output ->
            bitmap.compress(Bitmap.CompressFormat.JPEG, 80, output)
        }
        return outputFile.absolutePath
    }
}

